home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Mark Pilgrim / Ghost 1.0 / source / Ghost ƒ / Ghost code / ghost.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-30  |  3.8 KB  |  179 lines  |  [TEXT/KAHL]

  1. /**********************************************************************\
  2.  
  3. File:        ghost.c
  4.  
  5. Purpose:    This module handles game initialization, shutdown, and
  6.             event handling.
  7.  
  8.  
  9. Ghost -=- a classic word-building challenge
  10. Copyright (C) 1993 Mark Pilgrim
  11.  
  12. This program is free software; you can redistribute it and/or modify
  13. it under the terms of the GNU General Public License as published by
  14. the Free Software Foundation; either version 2 of the License, or
  15. (at your option) any later version.
  16.  
  17. This program is distributed in the hope that it will be useful,
  18. but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  20. GNU General Public License for more details.
  21.  
  22. You should have received a copy of the GNU General Public License
  23. along with this program in a file named "GNU General Public License".
  24. If not, write to the Free Software Foundation, 675 Mass Ave,
  25. Cambridge, MA 02139, USA.
  26.  
  27. \**********************************************************************/
  28.  
  29. #include "ghost globals.h"
  30. #include "ghost.h"
  31. #include "ghost setup.h"
  32. #include "ghost files.h"
  33. #include "ghost load-save.h"
  34. #include "ghost strategy.h"
  35. #include "ghost end.h"
  36. #include "ghost dictionary.h"
  37. #include "ghost error.h"
  38. #include "msg graphics.h"
  39. #include "msg menus.h"
  40. #include "msg environment.h"
  41. #include "msg timing.h"
  42. #include "msg dialogs.h"
  43. #include "msg sounds.h"
  44.  
  45. CIconHandle        gColorIcons[24];
  46. Handle            gBWIcons[24];
  47.  
  48. int                gNumComputerPlayers;
  49. StringHandle    gIconNames[24];
  50. int                gComputerIconIndex[5];
  51. int                gNumHumanPlayers;
  52. StringHandle    gHumanName[5];
  53. int                gHumanIconIndex[5];
  54.  
  55. Str255            gTheWord;
  56. Str255            gTheMessage;
  57. int                gCurrentPlayer;
  58.  
  59. int                gComputerPlayerScore[5];
  60. int                gHumanPlayerScore[5];
  61.  
  62. int                gNumPlayers;
  63. int                gPlayOrderIndex[10];
  64. int                gActualHumanPlayers;
  65. int                gActualComputerPlayers;
  66.  
  67. unsigned char    gShowMessageBox;
  68. unsigned char    gGameSpeed;
  69. unsigned char    gComputerIntelligence;
  70.  
  71. int                gStatus;
  72.  
  73. void InitGame(void)
  74. {
  75.     int            i,j,k;
  76.     AppFile        myFile;
  77.     Str255        tempStr;
  78.     
  79.     HandleError(LoadDictionary());
  80.     
  81.     if (gHasColorQD)
  82.         for (i=0; i<24; i++)
  83.             gColorIcons[i]=GetCIcon(128+i);
  84.     for (i=0; i<24; i++)
  85.         gBWIcons[i]=GetIcon(128+i);
  86.     for (i=0; i<24; i++)
  87.     {
  88.         GetIndString(tempStr, 130, i+1);
  89.         gIconNames[i]=NewString(tempStr);
  90.     }
  91.     for (i=0; i<10; i++)
  92.         gHumanName[i]=0L;
  93.     
  94.     CountAppFiles(&i, &j);
  95.     if ((j>0) && (i==0))
  96.     {
  97.         GetAppFiles(1, &myFile);
  98.         MyMakeFSSpec(myFile.vRefNum, 0, myFile.fName, &gameFile);
  99.         HandleError(GetSavedGame(&gameFile));
  100.         for (k=1; k<=j; k++)
  101.             ClrAppFiles(k);
  102.     }
  103. }
  104.  
  105. void NewGame(void)
  106. {
  107.     InitLoadSave();
  108.     if (GetHumanPlayers())
  109.     {
  110.         MakeComputerPlayers();
  111.         OrderPlayers();
  112.         if (gNumPlayers<2)
  113.         {
  114.             DoSound(sound_male_shoot, TRUE);
  115.             PositionDialog('ALRT', generalAlert);
  116.             ParamText("\pThere must be at least two players to play Ghost.","\p","\p","\p");
  117.             StopAlert(generalAlert, 0L);
  118.             return;
  119.         }
  120.         gCurrentPlayer=-1;
  121.         gActualComputerPlayers=gNumComputerPlayers;
  122.         gActualHumanPlayers=gNumHumanPlayers;
  123.         gTheWord[0]=0x00;
  124.         gInProgress=TRUE;
  125.         StartGame();
  126.     }
  127. }
  128.  
  129. void StartGame(void)
  130. {
  131.     StartTiming();
  132.     oldStartPtr=startPtr=listPtr=0L;
  133.     gTheMessage[0]=0x00;
  134.     gStatus=kNoStatus;
  135.     OpenMainWindow();
  136.     AdjustMenus();
  137.     NextPlayer();
  138. }
  139.  
  140. void GameUndo(void)
  141. {
  142. }
  143.  
  144. void GameEvent(void)
  145. {
  146. }
  147.  
  148. void GameKeyEvent(char charPressed)
  149. {
  150.     ObscureCursor();
  151.     if ((gInProgress) && (gPlayOrderIndex[gCurrentPlayer]<gNumHumanPlayers))
  152.     {
  153.         charPressed&=0xdf;
  154.         if ((charPressed>='A') && (charPressed<='Z'))
  155.             AddLetter(charPressed);
  156.     }
  157. }
  158.  
  159. void CheckForComputerPlayer(void)
  160. {
  161.     if (gInProgress)
  162.         if (gPlayOrderIndex[gCurrentPlayer]>=gNumHumanPlayers)
  163.             DoComputerPlayer();    
  164. }
  165.  
  166. void ShutDownGame(void)
  167. {
  168.     int            i;
  169.     
  170.     DisposeDictionary();
  171.     if (gHasColorQD)
  172.         for (i=0; i<24; i++)
  173.             DisposeCIcon(gColorIcons[i]);
  174.     for (i=0; i<24; i++)
  175.         ReleaseResource(gBWIcons[i]);
  176.     for (i=0; i<24; i++)
  177.         DisposeHandle(gIconNames[i]);
  178. }
  179.